require(['./config'], () =>{
    require(['header','footer'],()=>{
        class Register {
            constructor (){
                        this.registerName()
                        this.sureRegister()
                       
            }
            registerName(){
                $('#actual_username').blur(function(){
                    // console.log(123)
                    let reg = /^1[3-8]\d{9}$/,
                        username = $('#actual_username').val()
                         username = parseInt (username)
                        //  console.log(username)
                       if(username){
                            if(reg.test(username)){
                                let names = localStorage.getItem('name')
                                 names = JSON.parse(names)
                                
                                if(names === null){
                                    names = []
                                    localStorage.setItem('name',JSON.stringify(names))
                                }else{
                                   let sureBoolen = names.some(function (name){

                                         return name.username  == username
                            
                                    })
                                    // console.log(boolen)
                                    if(sureBoolen){
                                        $('#already_exist_name').html('您输入的手机已存在') 
                                    }else{
                                        $('#already_exist_name').html('') 
                                    }

                                }
                                
                            }else{
                                $('#already_exist_name').html('请输入正确的手机号') 
                            }
                        
                       }else{
                        $('#already_exist_name').html('不能为空')
                        //    console.log(456)
                       }
                       
                })
                this.registerPassword()
            }
            registerPassword(){
                
                   
                    $('#actual_password').blur (function(){
                        let password = $('#actual_password').val(),
                            ret = /^\w{6,10}$/
                            // console.log(password)
                        if(password){
                             if(ret.test(password)){
                                    $('#already_exist_password').html('') 
                                }else{
                                    $('#already_exist_password').html('密码不符合规则请重新输入')
                            
                                }
                            // $('#already_exist_password').html('')
                        }else{
                            $('#already_exist_password').html('不能为空')
                             
                        }
                        $('#actual_password_ture').blur(function(){
                            let truePassword = $('#actual_password_ture').val()
                            //  console.log(truePassword)
                                if(truePassword === password){
                                    $('#false_password').html('')
                                }else{
                                    $('#false_password').html('密码不一致')
                                }
                            })
                       
                    })          
             }
              sureRegister(){
                    
                 $('#btn_sureRegister').on('click',function(){
                    // console.log(123)
                    let checked = $('#checkbox_input').prop('checked')
                    if(checked === false){
                        alert('请先阅读')
                    }else{
                        
                        if($('#already_exist_name').html() ==="" &&  $('#already_exist_password').html()==="" &&  $('#false_password').html()==="" &&  $('#actual_username').val() != "" && $('#actual_password').val() != "" && $('#actual_password_ture').val() !="" ){
                        //    console.log(names)
                            let username  = $('#actual_username').val(),
                                password  = $('#actual_password').val(),
                                 names = localStorage.getItem('name')
                                 names = JSON.parse(names)
                                 names.push({
                                    username : username,
                                    password : password
                                }  
                                )
                            localStorage.setItem('name',JSON.stringify(names))
                            alert('注册成功即将跳转到登录页面')
                            location.href = '/html/login.html';
                            
                        }
                   }
                })
            }
            
                      
             
                




               
               
               
               
               




                //  })
                        







             




    }
        new Register ()








    })
})